/* Customization code for component BCInvoice */
&scoped-define class-version 263.0
{ definition/bcinvoice.i }
/* GY01 initial character value */
PROCEDURE BCInvoice.DefaultInvoiceTypes.after:

   define variable lvc_apmathingid as character no-undo.
   define variable lvi_return as integer no-undo.
   define variable vcUserLogin1 as character no-undo.
   define variable vcUserName1 as character no-undo.
   define variable lvi_msg_nbr   as  integer    no-undo. 
   define variable vcMfgDomain1  as  character  no-undo.
   define variable viReturn      as  INTEGER    NO-UNDO.
   define variable lvi_recnt      as  INTEGER    NO-UNDO.
   define variable lvc_activity  as   character   no-undo.
   define variable lvc_origref   as   character   no-undo.
   define variable lvi_session_id as integer   no-undo.
   define variable lvc_session_id as character no-undo.
   define variable lvh_session    as handle    no-undo.
   define variable lvc_value      as character extent 10 no-undo.
   
   
    output to /home/mfg/finlog/prod/BAPMatching/BCInvoice.DefaultInvoiceTypes.after.log.
   
    run getpublicdata(input "vcUserLogin", output vcUserLogin1 , output vireturn).
    run getpublicdata(input "vcUserName", output vcUserName1 , output vireturn).
    run getpublicdata(input "vcMfgDomain", output vcMfgDomain1 , output vireturn).
    
         run GetPublicData (input  "viSessionId",
                        output lvc_session_id,
                        output lvi_return).
    assign lvi_session_id = integer(lvc_session_id).

      run ins/ins__session.p persistent set lvh_session.

      run MainBlock in lvh_session
        (input 0,
         input 0,
         input 0,
         input no,
         input "",
         input-output lvi_session_id,
         output lvi_return).   


    if valid-handle(lvh_session)
    then do:
     do lvi_recnt = 1 to 10:
        
        lvc_value[lvi_recnt] = "".

         run SetCharacterValue in lvh_session
            (input "xx_lvc_apmathingid" + string(lvi_recnt)  ,
             input lvc_value[lvi_recnt],
             output lvi_return).		
             
             put unformatted vcMfgDomain1 " " lvi_session_id "  xx_lvc_apmathingid" + string(lvi_recnt)  "," lvc_value[lvi_recnt] "," lvi_return skip.       
             
     end.
             
    
    run StopInstance in lvh_session
         (input  "SAVE",
          input  "",
          input  "",
          input  no,
          output lvi_return).

         delete procedure lvh_session.
     end. /* if valid-handle(lvh_session) */


end procedure.
/*
PROCEDURE BCInvoice.DefaultValuesSupplier.before:

  

    define buffer b_cinvoice for CInvoice .
	define buffer b_creditor for Creditor .
	define buffer b_t_Parameter for t_Parameter .
	define variable preamount like CInvoice.cinvoicebalancetc .
    define variable vcompany as character .
    define variable viReturn      as  INTEGER    NO-UNDO.
    define variable vccompany1  as  character  no-undo.
    define variable viReturn1     as  INTEGER    NO-UNDO.
	
	
viReturn = 0.
output to value("/home/mfg/tcinvoice" + string(time) + ".txt").


run getpublicdata(input "vgCompanyId", output vccompany1 , output viReturn1).

/*put unformatted vccompany1 skip.*/


for each b_t_Parameter.

find first b_creditor no-lock where b_creditor.CreditorCode =  b_t_Parameter.bcCreditorCode no-error.
    put unformatted b_creditor.Creditor_id   skip.
	for each b_cinvoice where b_cinvoice.CinvoiceType = "PREPAYMENT"
                      and b_cinvoice.CInvoiceIsOpen
                      and b_cinvoice.creditor_id = b_creditor.Creditor_id 
					  and b_cinvoice.company_id = int64(vccompany1)
                      no-lock.
		preamount = preamount + b_cinvoice.cinvoicebalancetc.			
	end.
    put unformatted preamount   skip.
	if preamount <> 0 then do:
    t_Parameter.oiReturnStatus = +1.
	
	
    RUN setMessage
    (INPUT "此供应商有未结预付账款存在,金额为" + string(preamount),
     INPUT "",
     INPUT "",
     INPUT  "",
     INPUT "W",
     INPUT 3,
     INPUT "",
     INPUT "0",
     INPUT "",
     INPUT "",
     INPUT "",
     OUTPUT viReturn).
     
     
	
	leave.


/*put unformatted b_t_Parameter.bcCreditorCode*/


	end. /*end if*/

 output close. 

end.



END PROCEDURE.
*/

PROCEDURE BCInvoice.CheckDuplicateCInvoiceReference.after:
    define buffer b_cinvoice for CInvoice .
	define buffer b_creditor for Creditor .
	define buffer b_t_Parameter for t_Parameter .
	define variable preamount like CInvoice.cinvoicebalancetc .
    define variable vcompany as character .
    define variable viReturn      as  INTEGER    NO-UNDO.
    define variable vccompany1  as  character  no-undo.
    define variable viReturn1     as  INTEGER    NO-UNDO.
	
	
viReturn = 0.
preamount = 0.

output to value("/home/mfg/tcinvoice" + string(time) + ".txt").

for each xxqpmesc_ctrl no-lock.

disp xxqpmesc_ctrl with 3 col.

end.

run getpublicdata(input "vgCompanyId", output vccompany1 , output viReturn1).

/*put unformatted vccompany1 skip.*/

/*
for each b_t_Parameter.

find first b_creditor no-lock where b_creditor.CreditorCode =  b_t_Parameter.bcCreditorCode no-error.
    put unformatted b_creditor.Creditor_id   skip.
	for each b_cinvoice where b_cinvoice.CinvoiceType = "PREPAYMENT"
                      and b_cinvoice.CInvoiceIsOpen
                      and b_cinvoice.creditor_id = b_creditor.Creditor_id 
					  and b_cinvoice.company_id = int64(vccompany1)
                      no-lock.
		preamount = preamount + b_cinvoice.cinvoicebalancetc.			
	end.
    put unformatted preamount   skip.
	
	

	
	if preamount <> 0 then do:

    RUN setMessage
    (INPUT "此供应商有未结预付账款存在,金额为" + string(preamount),
     INPUT "",
     INPUT "",
     INPUT  "",
     INPUT "W",
     INPUT 3,
     INPUT "",
     INPUT "0",
     INPUT "",
     INPUT "",
     INPUT "",
     OUTPUT viReturn).
     
         t_Parameter.oiReturnStatus = +1.
	
	leave.


/*put unformatted b_t_Parameter.bcCreditorCode*/


	end. /*end if*/

END.	
*/


find first tCinvoice no-lock no-error.

find first b_creditor no-lock where b_creditor.CreditorCode =  tCinvoice.tcCreditorCode no-error.

	for each b_cinvoice where b_cinvoice.CinvoiceType = "PREPAYMENT"
                      and b_cinvoice.CInvoiceIsOpen
                      and b_cinvoice.creditor_id = b_creditor.Creditor_id 
					  and b_cinvoice.company_id = int64(vccompany1)
                      no-lock.
		preamount = preamount + b_cinvoice.cinvoicebalancetc.			
	end.
	/*	put unformatted preamount  skip.   */
	


if preamount <> 0 then do:

    RUN setMessage
    (INPUT "此供应商有未结预付账款存在,金额为" + string(preamount),
     INPUT "",
     INPUT "",
     INPUT  "",
     INPUT "W",
     INPUT 3,
     INPUT "",
     INPUT "0",
     INPUT "",
     INPUT "",
     INPUT "",
     OUTPUT viReturn).
     
         t_Parameter.oiReturnStatus = +1.
	
	leave.

    
/*put unformatted b_t_Parameter.bcCreditorCode*/


	end. /*end if*/

	

 output close. 


END PROCEDURE.
